package com.leo;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Point3D;
import javafx.scene.DepthTest;
import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Box;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.stage.Stage;

/**
 * @ClassName BoxDemo
 * @Description
 * @Author wangss
 * @date 2020.07.04 19:03
 * @Version 1.0
 */
public class BoxDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();

        HBox hBox = new HBox(100);
        ObservableList<Node> list = hBox.getChildren();
        for (int i = 0; i < 5; i++) {
            Box box = new Box(100, 100, 200);
            list.add(box);
        }

        Box b0 = (Box) hBox.getChildren().get(0);
//        b1.setTranslateX(-50);
        // 沿着那个轴旋转
        b0.setRotationAxis(new Point3D(1, 0, 0));
        // 旋转多少度
        b0.setRotate(30);

        Box b1 = (Box) hBox.getChildren().get(1);
        // 填充方式
        b1.setDrawMode(DrawMode.LINE);

        Box b2 = (Box) hBox.getChildren().get(2);
        // 渲染方式
        b2.setCullFace(CullFace.BACK);

        an.setStyle("-fx-background-color: #FFFFFF00");
        an.getChildren().addAll(hBox);
        an.setDepthTest(DepthTest.ENABLE);
        AnchorPane.setTopAnchor(hBox, 100d);
        AnchorPane.setLeftAnchor(hBox, 100d);

        Scene scene = new Scene(an, 1200, 800, true);
        scene.setCamera(new PerspectiveCamera());

        primaryStage.setScene(scene);
        primaryStage.setTitle("3D介绍");
        primaryStage.setWidth(1200);
        primaryStage.setHeight(800);
        primaryStage.show();
    }
}
